package com.ving.test;

import com.ving.test.mybatis01.Configuration01;
import com.ving.test.mybatis01.session.SqlSession01;
import com.ving.test.mybatis01.session.SqlSessionFactory01;
import com.ving.test.mybatis01.session.SqlSessionFactoryBuilder01;
import com.ving.test.nativemybatis.entity.TestBean;
import com.ving.test.nativemybatis.mapper.TestMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by liuweijie on 2019-11-14.
 */
@Slf4j
public class VingMybatisTest01 {

    @Test
    public void test01() throws IOException {
        System.out.println( "Hello World!" );
        String resource = "mybatis01/vingmybatis-config01.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        Configuration01 configuration01 = new Configuration01(inputStream);
        System.out.println("=====1====");
        SqlSessionFactory01 sqlSessionFactory01 = new SqlSessionFactoryBuilder01().build(configuration01);
        SqlSession01 sqlSession = sqlSessionFactory01.openSession(configuration01);
        TestMapper mapper = sqlSession.getMapper(TestMapper.class);
        TestBean testBean = mapper.selectUser(5);
        System.out.println(testBean.toString());
    }

}
